<template>
  <div>
    <table align="center" width="300px">
      <tr>
        <td>名称</td>
        <td>价格</td>
        <td>操作</td>
      </tr>
      <tr v-for="i in from">
        <td>{{ i.name }}</td>
        <td>{{ i.price }}</td>
        <td>
          <a href="" style="text-decoration: none;color: red" @click.prevent="del(i.id)">删除</a>
        </td>
      </tr>
    </table>
  </div>
</template>

<script>
export default {
  name: "show_2",
  data() {
    return {
      from: []
    }
  },
  methods: {
    get() {
      this.$axios.get('/add').then(res => {
        if (res.data.code == 200) {
          this.from = res.data.matter
          console.log(res.data.matter)
        }
      })
    },
    del(id) {
      this.$axios.delete('/del?id=' + id).then(res => {
        if (res.data.code == 200) {
          alert('删除成功')
          this.get()
        }
      })
    }
  },
  mounted() {
    this.get()
  }
}
</script>

<style scoped>

</style>
